from datetime import datetime


# abstract response object
class AbstractResponse:
    def __init__(self):
        self.code = 0
        self.message = ""
        self.timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')


# single object response
class GeneralResponse(AbstractResponse):

    def __init__(self, payload):
        super().__init__()
        self.payload = payload

    @staticmethod
    def of(payload):
        r = GeneralResponse(payload)
        return r.__dict__

    @staticmethod
    def empty():
        r = GeneralResponse(None)
        return r.__dict__


# multiple objects response
class PageableResponse(AbstractResponse):

    def __init__(self, pageSize, pageIndex, currentRecords, totalRecords, totalPages, payload):
        super().__init__()
        self.pagination = PageableResult.of(pageSize, pageIndex, currentRecords, totalRecords, totalPages)
        self.payload = payload

    @staticmethod
    def of(pageSize, pageIndex, currentRecords, totalRecords, totalPages, payload):
        r = PageableResponse(pageSize, pageIndex, currentRecords, totalRecords, totalPages, payload)
        return r.__dict__

    @staticmethod
    def empty():
        r = PageableResponse(0, 0, 0, 0, 0, None)
        return r.__dict__


# page response summary
class PageableResult:

    def __init__(self, pageSize, pageIndex, currentRecords, totalRecords, totalPages):
        self.pageSize = pageSize
        self.pageIndex = pageIndex
        self.currentRecords = currentRecords
        self.totalRecords = totalRecords
        self.totalPages = totalPages

    @staticmethod
    def of(pageSize, pageIndex, currentRecords, totalRecords, totalPages):
        r = PageableResult(pageSize, pageIndex, currentRecords, totalRecords, totalPages)
        return r.__dict__
